home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / copymove.swg / 0005_Copy File #5.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  1.9 KB  |  49 lines

  1. { copy Files With certain extentions to a specific directory (Both
  2.  parameters specified at the command line or in a Text File).. I cannot
  3.  seem to find a command withing TP 6.0 to copy Files.. I have looked
  4.  several times through the manuals but still no luck.. I even asked the
  5.  teacher in Charge and he did not even know! Ok all you Programmers out
  6.  there.. Show your stuff.. If you Really want to be kind, help me out
  7.  on this..I am just starting in TP and this is all new to me!
  8. }
  9.  
  10. {$R-,I+} {Set range checking off, IOChecking on}
  11. {$M $400, $2000, $10000} {Make sure enough heap space}
  12. {    1k Stack, 8k MinHeap, 64k MaxHeap }
  13. Type
  14.         Buf = Array[0..65527] of Byte;
  15. Var
  16.         FileFrom, FileTo : File;
  17.         Buffer : ^Buf;
  18.         BytesToRead, BytesRead : Word;
  19.         MoreToCopy, IoStatus : Boolean;
  20.  
  21. begin
  22.         {Determine largest possible buffer useable}
  23.         If MaxAvail < 65528 then
  24.                 BytesToRead := MaxAvail
  25.         else
  26.                 BytesToRead := 65528;
  27.         Writeln('Program is using ', BytesToRead , ' Bytes of buffer');
  28.         GetMem(Buffer, BytesToRead);    {Grab heap memory For buffer}
  29.         Assign(FileFrom, 'File_1');
  30.         Assign(FileTo, 'File_2');
  31.         Reset(FileFrom, 1);     {Open File With 1Byte Record size}
  32.         ReWrite(FileTo, 1);
  33.         IoStatus := (IoResult = 0);
  34.         MoreToCopy := True;
  35.         While IoStatus and MoreToCopy do begin
  36.         {$I-}
  37.                 blockread(FileFrom, Buffer^, BytesToRead, BytesRead);
  38.                 blockWrite(FileTo, Buffer^, BytesRead);
  39.         {$I+}
  40.                 MoreToCopy := (BytesRead = BytesToRead);
  41.                 IoStatus := (IoResult=0);
  42.         end;
  43.         Close(FileTO);
  44.         Close(FileFrom);
  45.         FreeMem(Buffer, BytesToRead); {Release Heap memory}
  46.         If (not IoStatus) then
  47.             Writeln('Error copying File!!!');
  48. end.
  49.